
/*sessionStorage.setItem("userId","13466823855"); 
sessionStorage.setItem("name","周青青");
sessionStorage.setItem("jobnumber","3770,0");
sessionStorage.setItem("deptId","55088496");
sessionStorage.setItem("corp","qiyegongzuo");*/

var corp = GetQueryString('corp');
var nowDate = getDay(0);
if(corp=='' || corp == 'null' || corp == undefined || corp == null){
	corp = sessionStorage.getItem("corp");
}else{
	sessionStorage.setItem("corp",corp);
}
if(sessionStorage.getItem("name")){
		//$('#touxiang').text(sessionStorage.getItem("name").substring(sessionStorage.getItem("name").length-2,sessionStorage.getItem("name").length));
				$('#username').text(sessionStorage.getItem("name"));
				gettouxiang(sessionStorage.getItem("userId"));
				getzuzhi(sessionStorage.getItem("userId"));
				getstar();
				getlabel();
				getTypePingjia();
}else{	
	var _config ;
	$.ajax({
		type : "post",
		data:JSON.stringify({"pageUrl":location.href.replace(/\\&/g,'%26'),"corp":corp}),
		contentType: "application/json; charset=utf-8",
		async: false,
		url : "../dingding/getconfig",
		dataType : "json",
		success : function(suc) {
			_config = suc.config;
		}
	}); 
	dd.ready(function() {
		dd.runtime.permission.requestAuthCode({
			corpId: _config.corpId,
			onSuccess: function(result) {
				getuserId(result);
			},
			onFail : function(err) {
				alert("错误"+JSON.stringify(err))
			}
			
		});
	});
	function getuserId(result){
		$.ajax({
			url : '../dingding/ddEasy',
			type : 'POST',
			data:JSON.stringify({"code":result.code,"token":_config.token}),
			contentType: "application/json; charset=utf-8",
			dataType : "json",
			success : function(suc) {
				if(suc.status == '1002'){
					sessionStorage.setItem("userId",suc.userJson.mobile);
					sessionStorage.setItem("name",suc.userJson.name);
					sessionStorage.setItem("jobnumber",suc.userJson.jobnumber);
					sessionStorage.setItem("deptId",suc.userJson.department);
				}else{
					alert(suc.msg);
				}
			//	$('#touxiang').text(sessionStorage.getItem("name").substring(sessionStorage.getItem("name").length-2,sessionStorage.getItem("name").length));
				$('#username').text(sessionStorage.getItem("name"));
				gettouxiang(sessionStorage.getItem("userId"));
				getzuzhi(sessionStorage.getItem("userId"));
				getstar();
				getlabel();
				getTypePingjia();
			},
			error : function(xhr, errorType, error) {
				alert(errorType + ', ' + error);
			}
		});
	}
	dd.error(function(err) {
		alert('dd error: ' + JSON.stringify(err));
	});
}
$(document).ready(function(){
	/*alert('从现在到三月三十一号为测试期，请大家积极试用，三月三十一号将会将大家的测试数据全部清空，四月一号开始正式使用！');*/
	$("#searchtext").on("input",function(){
	$('#listid').html("");
	if($("#searchtext").val() == ""){
			$('#listid').append(
				'<div class="w94 add_mar_lrauto h50p fle_content_row fle_just_btw fle_alig_center" >'
				+'<div class="w50p h50p add_mar_r2 fs_13p align_center add_weight"></div>'
				+'<div class="fle_gro_1 w0 fle_content_col fle_just_eve fle_alig_center">'
				+'<div class="w100 h20p fle_content_row fle_just_start fle_alig_center">'
				+'<div class="w100 fs_14p">金虎便利</div>'
				+'</div></div>'
				+'<div class="w20p align_right" onclick = "next(105)">'
				+'<i class="iconfont gray">&#xe611;</i>'
				+'</div></div>'
				+'<div class="w94 add_mar_lrauto h50p fle_content_row fle_just_btw fle_alig_center" >'
				+'<div class="w50p h50p add_mar_r2 fs_13p align_center add_weight"></div>'
				+'<div class="fle_gro_1 w0 fle_content_col fle_just_eve fle_alig_center">'
				+'<div class="w100 h20p fle_content_row fle_just_start fle_alig_center">'
				+'<div class="w100 fs_14p">今度烘焙</div></div></div>'
				+'<div class="w20p align_right" onclick = "next(131)">'
				+'<i class="iconfont gray">&#xe611;</i>'
				+'</div></div>'	
			)
	}else{
		$.ajax({  
			url: "../../unite_platform/mobile_pingjia/get_search_user"
			,type:'post'
			,async: false
			,contentType: "application/json; charset=utf-8"
			,data:JSON.stringify({"name":$("#searchtext").val()}) 
			,dataType:'json'
			,success: function(res){
				console.log(res);
				var photohtml="";
				for(var i =0;i<res.data.length;i++){
					if(res.data[i].photo=='' || res.data[i].photo==undefined){
						photohtml='<div class="w40p h40p add_rad_8p bg_blue white add_mar_r2 fs_13p align_center add_weight">'+res.data[i].name.substring(res.data[i].name.length-2,res.data[i].name.length)+'</div>';
					}else{
						photohtml='<div class="w40p h40p add_rad_8p white add_mar_r2 fs_13p align_center add_weight"><img class="w100 add_rad_8p w40p h40p" src="'+res.data[i].photo+'" /></div>'
					}
					$('#listid').append(
						'<div class="w94 add_pad_lr3 h60p add_bor_b_gray fle_content_row fle_just_btw fle_alig_center" onclick = "pingjia(\''+res.data[i].userId+'\',\''+res.data[i].name+'\',0)">'
					 //  +'<div class="w40p h40p add_rad_8p bg_blue white add_mar_r2 fs_13p align_center add_weight">'+res.data[i].name.substring(res.data[i].name.length-2,res.data[i].name.length)+'</div>'
					   +photohtml
					   +'<div class="fle_gro_1 w0 fle_content_col fle_just_eve fle_alig_center">'
					   +'<div class="w100 h20p fle_content_row fle_just_start fle_alig_center">'
					   +'<div class="w50p fs_14p">'+res.data[i].name+'</div>'
					   +'</div>'
					   //+'<div class="w100 h20p fs_13p gray"></div>'
					   +'</div></div>'
					)
				}
			}
		});
	}
})
	
});	
//查询待评价信息
function getTypePingjia(){
	var jobnumber = sessionStorage.getItem("jobnumber");
	if(jobnumber.length == 4 || (jobnumber.length > 4 && jobnumber.indexOf(',') > -1 )){
		var sendData = {};
		sendData.shopcode=jobnumber;
		sendData.endDate=nowDate;
		sendData.startDate=nowDate;
		sendData.pingjiaFlag=0;
		console.log(12333);
		$.ajax({
			url: "../../unite_platform/mobile_page/pingjia/getTypePingjia"
			,type:'post'
//		,async: false
					,data:JSON.stringify(sendData)
					,contentType: "application/json; charset=utf-8"
						,dataType:'json'
							,success: function(res){
								console.log(res)
								if(res.success){
									var resdata = res.data;
									$('#daipingjiaSpan').text('(待评价'+res.data.length+'条)');
									$('#daipingjiaSpan').show()
									$('#daipingjiaSpan').addClass('orange');
								//	window.location.href='toPingjia_other_list?shopcode='+jobnumber;
								}else{
//				layer.alert(res.message);
								}
							}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			console.log(XMLHttpRequest);
			console.log(textStatus);
			console.log(errorThrown);
			hideloading();
		}
		});
	}
	
}
function gettouxiang(userId){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/get_touxiang"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"userid":sessionStorage.getItem("userId")}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			if(res.data.length>0 && res.data[0].photo != '' && res.data[0].photo != undefined){
				$('#touxiang').append('<img class="w100 add_rad_8p h70p w70p" src="'+res.data[0].photo+'" />');
			}else{
				$('#touxiang')[0].className = 'w70p h70p add_rad_10p  white add_mar_r2 fs_14p align_center add_weight bg_blue';
				$('#touxiang').text(sessionStorage.getItem("name").substring(sessionStorage.getItem("name").length-2,sessionStorage.getItem("name").length));
			}
		}
	});
}
function getzuzhi(userId){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/get_zuzhi"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"userid":sessionStorage.getItem("userId")}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			if(res.data.length>0){
				for(var i =0;i<res.data.length;i++){
				if(i==0)$('#zuzhi').append('<span>'+res.data[i].name.substring(0,4)+'</span>');
				else $('#zuzhi').append('<span>--'+res.data[i].name+'</span>');
				}
			}else{
				$('#zuzhi').append('<span>无</span>');
			}	
		}
	});
}
function getstar(){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/getstar"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"userId":sessionStorage.getItem("userId")}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
				layui.use(['rate'], function(){
				  var rate = layui.rate;
				  //基础效果
				  rate.render({
				    elem: '#star' 
			 		,text: false
					,readonly: true
					,value:res.data[0].star
				 })
				});
		}
	});

}
function getlabel(){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/get_label"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"userId":sessionStorage.getItem("userId")}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			if(res.data.length>0){
				for(var i=0;i<2;i++){
					if(res.data[i] != undefined && res.data[i].label_name != undefined){
						$('#label').append('<div class="add_inlblo add_mar_r2"><i class="iconfont fs_12p orange">&#xe620;</i><span class="fs_12p fs_6rem gray_dark">'+res.data[i].label_name+'</span></div>');
					}
				}
				if(res.data.length>0){
					$('#label').append('<div class="fle_gro_1 align_right fs_12p blue" onclick="pingjia_detail()">'+res.data[0].sum+'评价<i class="iconfont fs_12p">&#xe611;</i></div>');
				}
			}
			
		}
	});
}
function next(groupId){
	 var  url = "pingjia_check?pId="+groupId;//此处拼接内容
	 window.location.href = url;
}
function pingjia_detail(){
	 var  url = "pingjia_detail?userId="+sessionStorage.getItem("userId");//此处拼接内容
	 window.location.href = url;
}

function pingjia(userId,username,type){
	 var  url = "pingjia_woyaopj?userId="+userId+'&username='+encodeURI(encodeURI(username))+'&type='+type;//此处拼接内容
	 window.location.href = url;
}
function dpj(groupId){
	var jobnumber = sessionStorage.getItem("jobnumber");
	window.location.href='toPingjia_other_list?shopcode='+jobnumber;
}